home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Games Extra 1996 September
/
Amiga Games Extra CD-ROM 9-1996.iso
/
userbox
/
publicdomain
/
wbstars
/
source
/
wbstars_plot.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-09
|
4KB
|
220 lines
/* $VER: WBStars_plot.c 1.02 (09.07.1996) */
#include "WBStars_include.h"
#include "WBStars_protos.h"
#include "WBStars_gui.h"
#define SCX(x) ((short)(((0.5*(x)/SCB)+0.5)*((double)maxx)))
#define SCY(y) ((short)(((0.5*(y)/SCB)+0.5)*((double)maxy)))
#define leng(s) (sqrt(star[(s)].x3*star[(s)].x3+star[(s)].y3*star[(s)].y3+star[(s)].z3*star[(s)].z3))
#define rndneg() (2.0*((double)(rand()-INT_MAX/2))/(double)INT_MAX)
double COCH[10]={0.3, 1.0, 10.0, 39.0, 102.0, 214.0, 392.0, 656.0 ,1024.0 ,1516.0};
double SLEN;
double maxd;
double dx;
double dy;
double dz;
void NewStars()
{
char i;
SLEN=sqrt(sqrt((double)warpf));
maxd=2.0*c*(COCH[warpf]+1.0)/sqrt((double)warpf+1.0);
dx=-0.04*c*COCH[warpf]*sin(((double)az)*PI/180.0);
dy=-0.04*c*COCH[warpf]*sin(((double)he)*PI/180.0);
dz=-0.04*c*COCH[warpf]*cos(((double)az)*PI/180.0)*cos(((double)he)*PI/180.0);
for(i=0; i<anzstars; i++)
{
NewStar(i);
}
}
void NewStar( char i )
{
double azimut;
double height;
double temp;
azimut=rndneg()*PI;
height=rndneg()*PID2;
star[i].x3=maxd*sin(azimut);
star[i].y3=maxd*sin(height);
star[i].z3=maxd*cos(azimut)*cos(height);
if(star[i].z3<dz*SLEN+1.0)
{
if(dz>0.0)
{
temp=(dz*SLEN+1.0-star[i].z3)/dz;
star[i].z3=dz*SLEN+1.0;
star[i].x3=star[i].x3+dx*temp;
star[i].y3=star[i].y3+dy*temp;
if( leng(i)>maxd )
{
NewStar(i);
}
}
else
{
NewStar(i);
}
}
star[i].anzpoints=0;
}
void ClearStar( char i )
{
char n;
BYTE drmd;
if(star[i].anzpoints>0)
{
for( n=0; n<star[i].anzpoints; n++)
{
if( (mode==MODE_WIN) || (ReadPixel(RastP,star[i].x[n],star[i].y[n])==star[i].col[n]) )
{
drmd=RastP->DrawMode;
if((drmd==JAM1)||(drmd==JAM2))
{
SetAPen(RastP,bgpen);
WritePixel(RastP,star[i].x[n],star[i].y[n]);
}
else
{
Forbid();
SetDrMd(RastP,JAM1);
SetAPen(RastP,bgpen);
WritePixel(RastP,star[i].x[n],star[i].y[n]);
SetDrMd(RastP,drmd);
Permit();
}
}
}
star[i].anzpoints=0;
}
}
void PlotStar( char i )
{
double fx,fy,fx2,fy2,dz3;
short x,y,dx2,dy2,e,c1,c2;
short ix1=1,iy1=0;
short ix2=0,iy2=1;
char pix,n;
char color;
BYTE drmd;
star[i].x3=star[i].x3+dx;
star[i].y3=star[i].y3+dy;
star[i].z3=star[i].z3+dz;
if( (leng(i)>=maxd) || (star[i].z3<1.0) || (star[i].z3<1.0+SLEN*dz) )
{
NewStar(i);
}
fx2=star[i].x3/star[i].z3;
fy2=star[i].y3/star[i].z3;
fx=(star[i].x3-dx*SLEN)/(star[i].z3-dz*SLEN);
fy=(star[i].y3-dy*SLEN)/(star[i].z3-dz*SLEN);
star[i].anzpoints=0;
if( ((abs(fx2)<SCB)&&(abs(fy2)<SCB)) || ((abs(fx)<SCB)&&(abs(fy)<SCB)) )
{
if(warpf==0)
{
if(((abs(fx2)<SCB)&&(abs(fy2)<SCB))&&ReadPixel(RastP,SCX(fx2),SCY(fy2))==bgpen)
{
star[i].anzpoints=1;
star[i].x[0]=SCX(fx2);
star[i].y[0]=SCY(fy2);
star[i].col[0]=PEN[0]%anzcolors;
Forbid();
drmd=RastP->DrawMode;
if((drmd==JAM1)||(drmd==JAM2))
{
SetAPen(RastP,PEN[0]%anzcolors);
WritePixel(RastP,star[i].x[0],star[i].y[0]);
}
else
{
SetDrMd(RastP,JAM1);
SetAPen(RastP,PEN[0]%anzcolors);
WritePixel(RastP,star[i].x[0],star[i].y[0]);
SetDrMd(RastP,drmd);
}
Permit();
}
}
else
{
dx2=SCX(fx2)-SCX(fx);
dy2=SCY(fy2)-SCY(fy);
if(dx2<0)ix1=-1;
if(dy2<0)iy2=-1;
dx2=abs(dx2);
dy2=abs(dy2);
if(dx2<dy2)
{
pix=dy2+1;
ix2=ix1;
ix1=0;
iy1=iy2;
iy2=0;
c1=2*dx2;
e=c1-dy2;
c2=e-dy2;
}
else
{
pix=dx2+1;
c1=2*dy2;
e=c1-dx2;
c2=e-dx2;
}
x=SCX(fx2);
y=SCY(fy2);
dz3=dz*SLEN/((double)pix);
pix=min(pix,MAXPOINTS)-2;
for(n=0; n<pix; n++)
{
if((x>0)&&(x<maxx)&&(y>0)&&(y<maxy)&&(ReadPixel(RastP,x,y)==bgpen))
{
color=(unsigned char)abs(((double)npen)*(dz3*((double)n)/(dz*SLEN)));
star[i].x[star[i].anzpoints]=x;
star[i].y[star[i].anzpoints]=y;
star[i].col[star[i].anzpoints]=PEN[color]%anzcolors;
star[i].anzpoints++;
Forbid();
drmd=RastP->DrawMode;
if((drmd==JAM1)||(drmd==JAM2))
{
SetAPen(RastP,PEN[color]%anzcolors);
WritePixel(RastP,x,y);
}
else
{
SetDrMd(RastP,JAM1);
SetAPen(RastP,PEN[color]%anzcolors);
WritePixel(RastP,x,y);
SetDrMd(RastP,drmd);
}
Permit();
}
x=x+ix1;
y=y+iy1;
if(e<0)
{
e=e+c1;
}
else
{
e=e+c2;
x=x+ix2;
y=y+iy2;
}
}
}
}
}